//
//  YLSwitchRootController.m
//  YLFinanceService
//
//  Created by she1323 on 2017/8/23.
//  Copyright © 2017年 she1323. All rights reserved.
//

#import "YLSwitchRootController.h"
#import "YLNavigationController.h"
#import "WHTabbarControllerConfig.h"
#import "YLLoginViewController.h"
#import "YLAccountTool.h"
#import "YLHomeViewController.h"
#import "WHTabbarViewController.h"
#import "YLMineViewController.h"
#import "YLAccountTool.h"
#import "YLCertifiedPaymentViewController.h"
@implementation YLSwitchRootController

+ (void)switchRootController
{
    YLNavigationController *nav = [YLNavigationController alloc];
    
    if ([YLAccountTool account]) {
        WHTabbarControllerConfig *tabBarControllerConfig = [[WHTabbarControllerConfig alloc] init];
        [[UIApplication sharedApplication].delegate.window setRootViewController:tabBarControllerConfig.tabBarController];
         [self switchMineOrRealName];
        
    } else {
        nav = [nav initWithRootViewController:[[YLLoginViewController alloc] init]];
        [[UIApplication sharedApplication].delegate.window setRootViewController:nav];
    }
    
}

+ (void)switchMineOrRealName
{

    UITabBarController *tabBarCon = (UITabBarController *)[UIApplication sharedApplication].delegate.window.rootViewController;
    if (tabBarCon.viewControllers.count < 4) {
        return;
    }
     YLNavigationController *nav =  tabBarCon.viewControllers[3];
    if ([YLAccountTool account].authState != 1) {
    // 未认证
        YLCertifiedPaymentViewController *p = [[YLCertifiedPaymentViewController alloc] init];
        [nav setViewControllers:@[p]];
    } else {
         UIViewController *con = nav.viewControllers.firstObject;
         if ( ![con isKindOfClass:[YLMineViewController class]]) {
             YLMineViewController *mine = [[YLMineViewController alloc] init];
             [nav setViewControllers:@[mine]];
        }
    }
   
    
    
}

@end
